import { createRouter, createWebHashHistory } from 'vue-router'

// 公共布局(父路由一级)
const Layout = () => import('@/views/Layout')
// 子路由-二级
// 首页
const Home = () => import('@/views/Home')
// 商品详情
const Detail = () => import('@/views/Goods')
// 登录
const Login = () => import('@/views/Login')
// 购物车
const Cart = () => import('@/views/Cart')

// 配置路由规则
const routes = [
  // 创建路由实例
  {
    path: '/',
    component: Layout,
    children: [
      {
        path: '/',
        component: Home
      },
      {
        path: '/good/:id',
        component: Detail
      },
      {
        path: '/cart',
        component: Cart
      }
    ]
  }, {
    path: '/login',
    component: Login
  }
]

const router = createRouter({
  // 使用hash方式实现路由
  history: createWebHashHistory(),
  // 配置路由规则,
  routes
})

export default router
